

PACKAGE BODY Test_Parser IS


   -- Initialisation de la suite de test
   PROCEDURE Set_Up IS
   BEGIN
      Unit_Test_Assertions.Init;

      resultBool := False;

      Ada.Text_IO.New_Line;
      Ada.Text_IO.Put_Line("--------------------------------------------------------------------------------");
      Ada.Text_IO.Put_Line("## Suite de test de robustesse du parser XML ##");

   END Set_Up;


   -- Terminaison de la suite de test
   PROCEDURE Tear_Down (nbTest : OUT Integer; nbError : OUT Integer; name : OUT Dyn_Str.Unbounded_String) IS
   BEGIN

      nbTest := Unit_Test_Assertions.Get_Tests_Count;
      nbError := Unit_Test_Assertions.Get_Error_Count;
      name := Dyn_Str.To_Unbounded_String("test_parser");
      Ada.Text_IO.Put_Line("--------------------------------------------------------------------------------");
      Ada.Text_IO.New_Line;

   END Tear_Down;


   -- Demarrage de la suite de tests
   PROCEDURE Run IS
   BEGIN

      Test_FileNotFound ;

      Test_TagMissing ;

      Test_ContentWithoutTag;

      Test_UnopenedTag;

      Test_InitMark;

   END Run;


   -- Permet de verifier qu'une erreur a bien ete levee
   PROCEDURE Test_Error (fileName : IN String; testMessage : IN String)   IS
   BEGIN
      begin
         Ada.Text_IO.New_Line;
         resultBool := False;
         testRDP := Rdp.Xml_Build (fileName,"petrinet");
      exception
         when Xml_Readers.Xml_Reader_Error =>
            resultBool := True;
         when Xml_Iterators.Malformed_Xml_Error =>
            resultBool := True;
         when Rdp.Negative_Marking_Error =>
            resultBool := True;
         when others =>
            resultBool := False;
      end;

      Unit_Test_Assertions.Assert_Boolean (resultBool, True, testMessage);
   END Test_Error;


   -- Test de fichier non trouve
   PROCEDURE Test_FileNotFound IS
   BEGIN
      Test_Error ("data/test_parser/NotFound.xml", "  #Fichier non trouve");
   END Test_FileNotFound;


   -- Test de balisage incomplet
   PROCEDURE Test_TagMissing IS
   BEGIN
      Test_Error("data/test_parser/ErrorTagMissing.xml", "  #Erreur de balisage (Balisage incomplet)");
   END Test_TagMissing;


   -- Test de contenu sans balise
   PROCEDURE Test_ContentWithoutTag IS
   BEGIN
      Test_Error ("data/test_parser/ErrorContentWithoutTag.xml", "  #Erreur de balisage (Contenu sans balisage)");
   END Test_ContentWithoutTag;


   -- Test de balise non ouverte
   PROCEDURE Test_UnopenedTag IS
   BEGIN
      Test_Error("data/test_parser/UnopenedTag.xml", "  #Erreur de balisage (Balise non ouverte)");
   END Test_UnopenedTag;


   -- Test d'erreur sur le marquage initial
   PROCEDURE Test_InitMark IS
   BEGIN
      Test_Error("data/test_parser/ErrorInitMark.xml", "  #Erreur marquage initial negatif");
   END Test_InitMark;

END Test_Parser;
